
#include "dios_ssp_mchpf_api.h"
#include "dios_ssp_hpf_api.h"

#define MAXMICNUM 16

typedef struct objMCHPF_
{
    int mic_num;
    void *ptr_hpf[MAXMICNUM];
} objMCHPF;

void* dios_ssp_mchpf_init_api(int mics)
{
    if (mics > MAXMICNUM)
    {
        return NULL;
    }

    void* ptr = NULL;
    objMCHPF *srv;
    ptr = (void*)calloc(1, sizeof(objMCHPF));
    srv = (objMCHPF *)ptr;

    srv->mic_num = mics;

    for (int m = 0; m < srv->mic_num; m++)
    {
        srv->ptr_hpf[m] = dios_ssp_hpf_init_api();
    }

    return ptr;
}


int dios_ssp_mchpf_reset_api(void* ptr)
{
    if (NULL == ptr)
    {
        return -1;
    }
    objMCHPF *srv;
    srv = (objMCHPF *) ptr;

    int ret;
    for (int m = 0; m < srv->mic_num; m ++)
    {
        ret = dios_ssp_hpf_reset_api(srv->ptr_hpf[m]);
        if (ret != 0)
        {
            return -1;
        }
    }

    return 0;
}

int dios_ssp_mchpf_process_api(void* ptr, float* io_buf, int framelen, int mics)
{
    if (NULL == ptr)
    {
        return -1;
    }
    objMCHPF *srv;
    srv = (objMCHPF *) ptr;
    int ret;

    if (mics > srv->mic_num)
    {
        return -1;
    }

    for (int m = 0; m < mics; m ++)
    {
        ret = dios_ssp_hpf_process_api(srv->ptr_hpf[m], io_buf + m * framelen, framelen);
        if (ret != 0)
        {
            return -1;
        }
    }

    return 0;
}

int dios_ssp_mchpf_uninit_api(void* ptr)
{
    if (NULL == ptr)
    {
        return -1;
    }
    objMCHPF *srv;
    srv = (objMCHPF *) ptr;
    int ret;

    for (int m = 0; m < srv->mic_num; m ++)
    {
        ret = dios_ssp_hpf_uninit_api(srv->ptr_hpf[m]);
        if (ret != 0)
        {
            return -1;
        }
    }

    return 0;
}
